/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-07-21     lalala       the first version
 */
#include "display.h"
#include "ssd1306_tests.h"
#include "onenet_connect.h"
#include "string.h"
#include "IM1281B.h"
char sprintf_buf[30] = {0};
unsigned long   Voltage_data=0,Current_data=0,Power_data=0,Energy_data=0,Pf_data=0;
char Vol_d[30] = {0},Cur_d[30] = {0},Pow_d[30] = {0},Enr_d[30] = {0},PF_d[30] = {0};
void display(void)
{
    ssd1306_Init();
    rt_thread_mdelay(100);
    int cp = 0;
//    ssd1306_Fill(White);
    while(1)
    {
//        ssd1306_Fill(White);
        sprintf(sprintf_buf,"%.3f",25.94);
        ssd1306_SetCursor(0, 0);
        ssd1306_WriteString("Vol_d:",Font_7x10,White);
        ssd1306_SetCursor(0+50, 0);
        ssd1306_WriteString(sprintf_buf,Font_7x10,White);
        ssd1306_UpdateScreen();
        memset(sprintf_buf,0,sizeof(sprintf_buf));
        ////
        sprintf(sprintf_buf,"%.3f",0.02);
        ssd1306_SetCursor(0, 0+16);
        ssd1306_WriteString("Cur_d:",Font_7x10,White);
        ssd1306_SetCursor(42, 0+16);
        ssd1306_WriteString(sprintf_buf,Font_7x10,White);
        ssd1306_UpdateScreen();
        memset(sprintf_buf,0,sizeof(sprintf_buf));
        //
        sprintf(sprintf_buf,"%.3f",25.94*0.02);
                ssd1306_SetCursor(0, 0+16+10);
                ssd1306_WriteString("Pow_d:",Font_7x10,White);
                ssd1306_SetCursor(42, 0+16+10);
                ssd1306_WriteString(sprintf_buf,Font_7x10,White);
                ssd1306_UpdateScreen();
                memset(sprintf_buf,0,sizeof(sprintf_buf));
                //
                sprintf(sprintf_buf,"%.3f",0.001);
                ssd1306_SetCursor(0, 0+16+10+10);
                ssd1306_WriteString("Enr_d:",Font_7x10,White);
                ssd1306_SetCursor(42, 0+16+10+10);
                ssd1306_WriteString(sprintf_buf,Font_7x10,White);
                ssd1306_UpdateScreen();
                memset(sprintf_buf,0,sizeof(sprintf_buf));
                //
                sprintf(sprintf_buf,"%.3f",0.924);
                ssd1306_SetCursor(0, 0+16+30);
                ssd1306_WriteString("PF_d:",Font_7x10,White);
                ssd1306_SetCursor(42, 0+16+30);
                ssd1306_WriteString(sprintf_buf,Font_7x10,White);
                ssd1306_UpdateScreen();
                memset(sprintf_buf,0,sizeof(sprintf_buf));


    }


}

void display_init(void)
{
       rt_thread_t thread = rt_thread_create("display_init", display, RT_NULL, 1024, 15, 100);
       if (thread != RT_NULL)
       {
                  rt_thread_startup(thread);
       }
//       rt_kprintf("ESP8266_SEND DATA is run!!!\r\n");
}
INIT_APP_EXPORT(display_init);



